package com.solution.admin.order.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.solution.admin.order.dao.OrderDetailDao;
import com.solution.admin.order.entity.OrderDeliveredBillEntity;
import com.solution.admin.order.entity.OrderDetailEntity;
import com.solution.common.dao.impl.BaseDaoImpl;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;

/**
 * 订单商品详情DAO实现
 * @author lilp
 * @date 2017-09-15 18:31:33
 */
@Repository
public class OrderDetailDaoImpl extends BaseDaoImpl<OrderDetailEntity> implements OrderDetailDao {

	/**
	 * 保存订单商品详情信息
	 * @param orderDetailEntity
	 * @return
	 * @author lilp
	 * @date 2017-09-15 18:31:33
	 */
	@Override
	public long saveOrderDetail(OrderDetailEntity orderDetailEntity) {
		return super.insert(orderDetailEntity);
	}

	/**
	 * 分页查询订单商品详情信息
	 * @param pageParam 分页对象
	 * @param orderDetail 分页参数
	 * @return PageBean 分页参数及数据
	 * @author lilp
	 * @date 2017-09-15 18:31:33
	 */
	public PageBean listOrderDetailPage(PageParam pageParam, Map<String, Object> param) {
		return super.listPage(pageParam, param);
	}

	/**
	 * 更新订单商品详情
	 * @param orderDetailEntity
	 * @return
	 * @author lilp
	 * @date 2017-09-15 18:31:33
	 */
	@Override
	public int updateOrderDetail(OrderDetailEntity orderDetailEntity) {
		return super.update(orderDetailEntity);
	}

	/**
	 * 删除订单商品详情
	 * @param orderDetailId
	 * @return
	 * @author lilp
	 * @date 2017-09-15 18:31:33
	 */
	public int deleteOrderDetailById( Long id) {
		return super.deleteById(id);
	}
	
	/**
	 * 根据条件查询订单商品详情
	 * @param param
	 * @return
	 * @author lilp
	 * @date 2017-09-15 18:31:33
	 */
	@Override
	public List<OrderDetailEntity> listOrderDetail( Map<String, Object> param) {
		return super.listBy(param);
	}
	
	/**
	 * 批量修改订单商品调价
	 * @param orderDetailList
	 * @return
	 */
	@Override
	public int batchAdjustOrderProductPrice(List<OrderDetailEntity> orderDetailList){
		return getSessionTemplate().update(getStatement("batchUpdateOrderProductPrice"),orderDetailList);
	}
	
	
	/**
	 * 批量插入订单详情
	 * @param orderDetailList
	 * @return
	 * @author lilp
	 */
	public int saveOrderDetailBatch(List<OrderDetailEntity> orderDetailList){
		return getSessionTemplate().update(getStatement("batchInsertOrderDetail"),orderDetailList);
	}
	
	/**
	 * 更新订单详情商品已发货数量
	 * @param param1
	 */
	public int updateOrderDetailSendNum(Map<String, Object> param1){
		return getSessionTemplate().update(getStatement("updateOrderDetailSendNum"),param1);
	}
	
	/**
	 * 查询订单未发货商品数量
	 * @param param
	 * @return
	 */
	public int selectNotDeliveredNum(Map<String, Object> param){
		return getSessionTemplate().selectOne("selectNotDeliveredNum", param);
	}
	
	/**
	 * 修改订单详情表的send_num 字段发货数量 = 购买数量(全部发货)
	 * @param param
	 */
	public int updateOrderDetailSendNumToBuyNum(Map<String, Object> param){
		return getSessionTemplate().update(getStatement("updateOrderDetailSendNumToBuyNum"),param);
	}
}
